package com.gy.studyonlineapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gy.studyonlineapp.entity.Knowledge;
import com.gy.studyonlineapp.R;
import com.gy.studyonlineapp.entity.KnowledgeItem;
import com.gy.studyonlineapp.layout.MyImageView;

import java.util.List;

public class KnowledgeAdapter extends ArrayAdapter<KnowledgeItem> {
    private int resourceId;

    public KnowledgeAdapter(Context context,  int resourceId, List<KnowledgeItem> list) {
        super(context, resourceId, list);
        this.resourceId = resourceId;
    }
    @Override //加载knowledge_item自定义布局
    public View getView(int position, View convertView, ViewGroup parent) {
        KnowledgeItem item = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        MyImageView knowledgeImage =  view.findViewById(R.id.knowledge_image);
        TextView knowledgeName =  view.findViewById(R.id.knowledge_name);
        TextView objectId = view.findViewById(R.id.ad_objectId);
        objectId.setText(item.getId());
        knowledgeImage.setImageURL(item.getImageUrl());
        knowledgeName.setText(item.getTitle());
        return view;
    }
}
